import React, { Component } from 'react'
import axios from 'axios'
import Header from '../../../components/header'


export default class Record extends Component {

   
    state={
        list:[]
    }

   
    render() {
        const { list } = this.state
        return (
            <div>
                <Header />

                {/* 第一种传参方式: 通过location */}
                {/* {
                    list.map(item=>{
                        return <div key={item.orderId} onClick={()=>this.props.history.push({pathname:'/detail',state:{id:item.orderId}})}>
                            {item.orderId}--{item.price}
                        </div>
                    })
                } */}


                {/* 第二种传参方式：动态路由 */}
                {
                    list.map(item=>{
                        return <div key={item.orderId} onClick={()=>this.props.history.push('/detail/'+item.orderId+'/'+item.price)}>
                            {item.orderId}--{item.price}
                        </div>
                    })
                }
            </div>
        )
    }
    componentDidMount(){
      localStorage.user&&axios.get('/list/record').then(res=>{
            const {code,data} = res.data
            if(code === 1){
                this.setState({list:data})
            }
        })
    }

}
